package com.xdb.sqlparser.dialect.mysql.ast.statement;

import com.xdb.sqlparser.ast.SQLOrderBy;
import com.xdb.sqlparser.ast.statement.SQLUpdateStatement;
import com.xdb.sqlparser.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit;
import com.xdb.sqlparser.dialect.mysql.visitor.MySqlASTVisitor;
import com.xdb.sqlparser.visitor.SQLAstVisitor;
import com.xdb.util.JDBCConstants;

public class MySqlUpdateStatement extends SQLUpdateStatement implements MySqlStatement {

	private SQLOrderBy orderBy;
	private Limit limit;

	private boolean lowPriority = false;
	private boolean ignore = false;

	public MySqlUpdateStatement() {
		super(JDBCConstants.MYSQL);
	}

	public Limit getLimit() {
		return limit;
	}

	public void setLimit(Limit limit) {
		if (limit != null) {
			limit.setParent(this);
		}
		this.limit = limit;
	}

	@Override
	protected void accept0(SQLAstVisitor visitor) {
		if (visitor instanceof MySqlASTVisitor) {
			accept0((MySqlASTVisitor) visitor);
		} else {
			throw new IllegalArgumentException("not support visitor type : " + visitor.getClass().getName());
		}
	}

	public void accept0(MySqlASTVisitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, tableSource);
			acceptChild(visitor, items);
			acceptChild(visitor, where);
			acceptChild(visitor, orderBy);
			acceptChild(visitor, limit);
		}
		visitor.endVisit(this);
	}

	public boolean isLowPriority() {
		return lowPriority;
	}

	public void setLowPriority(boolean lowPriority) {
		this.lowPriority = lowPriority;
	}

	public boolean isIgnore() {
		return ignore;
	}

	public void setIgnore(boolean ignore) {
		this.ignore = ignore;
	}

	public SQLOrderBy getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(SQLOrderBy orderBy) {
		this.orderBy = orderBy;
	}

}
